#include <fstream>
#include <map>
#include "newsgroup.h"
#include <sstream>
using namespace std;

template <typename T>
string to_string(T& number) { stringstream ss;
	ss << number;
	return ss.str();
}

template <typename T>
T from_string(string& s)
{
	istringstream is(s);
	T value;
	is >> dec >> value;
	return value;
}

typedef map<unsigned int, NewsGroup*> map_t;
typedef map<unsigned int, NewsGroup*>::iterator map_itr_t;
class Database {
	public:
	~Database();
	virtual void insert(unsigned int, NewsGroup*);	
	virtual void erase(map_t::iterator);
	virtual void update(void);
	size_t size(void);
	map_itr_t begin();
	map_itr_t end();
	map_itr_t find(unsigned int&);
	NewsGroup* operator[] (const unsigned int&);
	protected:
	map_t mymap;
};

class DatabaseDisk : public Database {
	public:
	DatabaseDisk();
	~DatabaseDisk();
	void insert(unsigned int, NewsGroup*);
	void erase(map_itr_t itr);
	void update(void);
	private:
	void save_to_disc(void);
	ofstream out;
	ifstream in;		
};
